package com.itheima.edu.info.manager.day13;

import java.util.concurrent.locks.ReentrantLock;

public class ChiHanBao  implements Runnable {
    @Override
    public void run() {
        while (ZhuoZi.a != 0) {
            synchronized (ZhuoZi.o){
                if (ZhuoZi.f == true) {
                    System.out.println("吃汉堡");
                    ZhuoZi.a--;
                    ZhuoZi.f = false;

                    //沉睡和唤醒必须与锁一致
                    ZhuoZi.o.notifyAll();
                } else {
                    try {
                        //ZhuoZi.o.notifyAll();

                        //沉睡和唤醒必须与锁一致
                        ZhuoZi.o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
